export function toTree(data) {
  // 存储结果的空数组
  var res = []
  var map = {}
  // 循环遍历data 赋值给map
  data.forEach(item => {
    map[item.id] = item
  })
  // console.log(map)
  data.forEach(item => {
    const parent = map[item.pid]
    // console.log(parent)
    if (parent) {
      (parent.children || (parent.children = [])).push(item)
    } else {
      res.push(item)
    }
  })
  return res
}

